<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.loandd}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
            <h:form prependId="false">
               <script type="text/javascript">  
                   var doInitForm=false;
                   var tofocus;
                   
                   function changeFocus(nextfcs) {tofocus=nextfcs;}
                   function setDoInitForm(st) {doInitForm=st;}
                   function focusState(xhr, status, args) {  
                       //if(args.validationFailed || !args.success) {}
                       //else document.getElementById(tofocus).focus();
                       return false;
                   }
                   
                   function handleCompleteSaving(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {
                        }else setTimeout(function() {if (doInitForm==true) btnNewLoandd.jq.click();}, 3000);
                    }
                    
                    function customRK(e, id) {
                       var code = (e.keyCode ? e.keyCode : e.which);
                       if(code==13) {
                           if (id == 'loanddLoanno') {
                               rcloanddGetLoan();
                            }
                           
                           e.preventDefault ? e.preventDefault() : e.returnValue = false;
                           e.stopPropagation();
                       }
                    }
                    
                </script>  
                <p:toolbar >
                    <p:toolbarGroup align="left">
                        <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document" 
                                         action="#{loanddBean.newData()}" process="@this" update="displayLoandd, btnSaveLoandd" 
                                         widgetVar="btnNewLoandd" oncomplete="setDoInitForm(false);"
                                         rendered="#{menuBean.cekButtonAccess(304,'INS;')}">
                            <pe:resetEditableValues for="displayLoan"/>  
                        </p:commandButton>
                                                
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk"
                                         action="#{loanddBean.save()}"  id="btnSaveLoandd"
                                         rendered="#{menuBean.cekButtonAccess(304,'INS;')}"
                                         oncomplete="setDoInitForm(true); handleCompleteSaving(xhr, status, args);"
                                         update="displayLoandd, @this" disabled="#{!loanddBean.editMode}" >
                        </p:commandButton> 
                    </p:toolbarGroup>
                    
                    <p:toolbarGroup align="right">
                        <p:commandButton id="doNothingLoandd" type="button" value="" style="width: 0px; height: 0px;"/> 
                         <p:defaultCommand target="doNothingLoandd"/> 
                    </p:toolbarGroup>
                </p:toolbar>
                
                <p:remoteCommand name="rcloanddGetLoan" actionListener="#{loanddBean.getLoan('null')}" 
                                 update="displayLoandd loancddCustInfo hideLoanddLoanId" process="loanddLoanno @this"
                                 oncomplete="focusState(xhr, status, args);"/>
                
                <!-- LOOK UP saving -->
                <p:dialog header="#{bundle.Select} #{bundle.loanNo}" widgetVar="dlgLoanddLookupLoan" closable="true" dynamic="true" >
                    <p:ajax listener="#{loanddBean.handleCloseLookup}" />
                    <h:panelGrid id="displayLoanddLookup" rendered="#{loanddBean.showLookup==true}">
                        <ui:include src="../loan/searchLoan.xhtml" >
                            <ui:param name="lookupLoanComponenId" value="loandd" />
                            <ui:param name="loanApprovalUid" value="#{1}" />
                            <ui:param name="loanStatusLoan" value="#{2}" />
                            
                        </ui:include> 

                        <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR" >
                            <f:facet name="footer">
                                <p:commandButton value="#{bundle.btnOK}" icon="ui-icon-disk" immediate="true" 
                                                process="@this" update="displayLoandd"
                                                action="#{loanddBean.getLoan(searchLoanBean.selectedData.loanNo)}" 
                                                oncomplete="dlgLoanddLookupLoan.hide(); focusState(xhr, status, args);" />

                                <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgLoanddLookupLoan.hide()" immediate="true" icon="ui-icon-document" process="@this" />
                            </f:facet>
                        </h:panelGrid>
                    </h:panelGrid>    
                </p:dialog>
                
                <h:panelGrid id="displayLoandd" styleClass="addELIT">
                    <h:panelGrid columns="2" rowClasses="panelGridId" >
                        <p:panel header="#{bundle.loanLedgend}">
                            <h:panelGrid columns="3" cellpadding="0" cellspacing="10" >
                                <h:outputLabel value= "#{bundle.ddNo}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.ddNo}" />
                                                                
                                <h:outputLabel style="padding:0 15px 0 0;" value= "#{bundle.ddDate}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.ddDate}" />

                                <p:outputLabel value= "#{bundle.loanNo}" for="loanddLoanno"/><h:outputLabel value= ":" />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                    <p:inputText value="#{loanddBean.loandd.loan.loanNo}" 
                                                onkeydown="customRK(event, 'loanddLoanno')" 
                                                id="loanddLoanno" label="#{bundle.loanNo}" disabled="#{!loanddBean.authorized}"
                                                required="true" requiredMessage="#{bundle.loanNo} #{bundle.requiredInput}" />
                                    
                                    <p:commandButton icon="ui-icon-search" iconPos="center" styleClass="btnSmall"
                                                     update="displayLoanddLookup" 
                                        process="@this" immediate="true" oncomplete="dlgLoanddLookupLoan.show();" disabled="#{!loanddBean.authorized}">
                                        <f:setPropertyActionListener target="#{loanddBean.showLookup}" value="#{true}" />
                                    </p:commandButton>
                                </h:panelGrid>
                                
                                <h:outputLabel value= "#{bundle.loanDate}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.loan.loanDate}" />

                                <h:outputLabel value= "#{bundle.loanprod}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.loan.loanprod.productName}" />

                                <h:outputLabel value= "#{bundle.loanAmount}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.loan.principalAmount}" >
                                    <f:convertNumber groupingUsed="true" />
                                </h:outputText>
                                
                                <h:outputLabel value= "#{bundle.fee}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.fee}" >
                                    <f:convertNumber groupingUsed="true" />
                                </h:outputText>
                                
                                <h:outputLabel value= "#{bundle.sisa}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.owing}" >
                                    <f:convertNumber groupingUsed="true" />
                                </h:outputText>
                                
                                <!-- validasi loanId -->
                                <h:inputHidden value="#{loanddBean.loandd.loan.loanId}" required="true" id="hideLoanddLoanId"
                                    requiredMessage="#{bundle.loanNo} #{loanddBean.loandd.loan.loanNo} #{bundle.dataNotFound}" />
                                
                            </h:panelGrid>
                        </p:panel>

                        <p:outputPanel autoUpdate="true">
                            <p:panel header="#{bundle.cusledgen}" id="loancddCustInfo">
                            <h:panelGrid columns="3" cellpadding="0" cellspacing="10" style="width: 100%" >
                                <h:outputLabel value= "#{bundle.cif}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.loan.customer.cif}" />

                                <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.loan.customer.customerName}" />

                                <h:outputLabel value= "#{bundle.aliasName}" /><h:outputLabel value= ":" />
                                <h:outputText rendered="true" value="#{loanddBean.loandd.loan.customer.aliasName}" />

                                <h:outputLabel value= "#{bundle.npwp}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.loan.customer.npwp}" />

                                <h:outputLabel style="padding: 0 15px 0 0;" value= "#{bundle.officePhone}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.loan.customer.cusper.officePhone}"/>

                                <h:outputLabel value= "#{bundle.phone}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.loan.customer.phone}"/>

                                <h:outputLabel value= "#{bundle.mobilePhone}" /><h:outputLabel value= ":" />
                                <h:outputText value="#{loanddBean.loandd.loan.customer.mobilePhone}"/>
                                
                                <h:outputLabel value= "#{bundle.specimen}" /><h:outputLabel value=":"/>
                                <p:graphicImage  value="/upload/personal/#{loanddBean.loandd.loan.customer.specimen}" />
                                
                            </h:panelGrid>
                        </p:panel>
                        </p:outputPanel>
                    </h:panelGrid>
                </h:panelGrid>           
            </h:form> 
        </ui:composition>            
    </h:body>
</html>